
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <title>8.Alloc实现 · MPUSH开发文档</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.0">
        <meta name="author" content="夜色">
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-navigator/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="chapter15.html" />
    
    
    <link rel="prev" href="chapter14.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    0.Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="chapter1.html">
            
                <a href="chapter1.html">
            
                    
                    1.系统架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="chapter2.html">
            
                <a href="chapter2.html">
            
                    
                    2.服务依赖关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="chapter3.html">
            
                <a href="chapter3.html">
            
                    
                    3.协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="chapter4.html">
            
                <a href="chapter4.html">
            
                    
                    4.主要流程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="chapter6.html">
            
                <a href="chapter6.html">
            
                    
                    4.1.密钥交换方案
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="chapter7.html">
            
                <a href="chapter7.html">
            
                    
                    4.2.握手及快速重连
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="chapter8.html">
            
                <a href="chapter8.html">
            
                    
                    4.3.绑定用户及路由发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="chapter9.html">
            
                <a href="chapter9.html">
            
                    
                    4.4.解绑用户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="chapter10.html">
            
                <a href="chapter10.html">
            
                    
                    4.5.消息推送
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="chapter11.html">
            
                <a href="chapter11.html">
            
                    
                    4.6.Http代理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="chapter12.html">
            
                <a href="chapter12.html">
            
                    
                    5.服务部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="chapter13.html">
            
                <a href="chapter13.html">
            
                    
                    6.源码测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="chapter14.html">
            
                <a href="chapter14.html">
            
                    
                    7.配置详解
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.9" data-path="chapter17.html">
            
                <a href="chapter17.html">
            
                    
                    8.Alloc实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="chapter15.html">
            
                <a href="chapter15.html">
            
                    
                    9.Android SDK
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="chapter15.1.html">
            
                <a href="chapter15.1.html">
            
                    
                    9.1.SDK系统架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="chapter15.2.html">
            
                <a href="chapter15.2.html">
            
                    
                    9.2.MpushClient架构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="chapter16.md">
            
                <span>
            
                    
                    10.IOS SDK
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="chapter18.html">
            
                <a href="chapter18.html">
            
                    
                    11.服务端SDK
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="chapter19.html">
            
                <a href="chapter19.html">
            
                    
                    12.HTTP代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="chapter20.html">
            
                <a href="chapter20.html">
            
                    
                    13.Server源码分析
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="chapter20.1.html">
            
                <a href="chapter20.1.html">
            
                    
                    13.1.模块依赖关系
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="chapter21.html">
            
                <a href="chapter21.html">
            
                    
                    14.SPI定制化
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >8.Alloc实现</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="Alloc&#x5B9E;&#x73B0;">Alloc&#x5B9E;&#x73B0;</h1><h2 id="alloc_&#x7684;&#x4F5C;&#x7528;">1. alloc &#x7684;&#x4F5C;&#x7528;</h2><blockquote><ul><li>alloc &#x662F;&#x9488;&#x5BF9;client&#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x4E2A;&#x8F7B;&#x91CF;&#x7EA7;&#x7684;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x670D;&#x52A1;
</li>
<li>&#x6BCF;&#x6B21;&#x5BA2;&#x6237;&#x7AEF;&#x5728;&#x94FE;&#x63A5;MPUSH server&#x4E4B;&#x524D;&#x90FD;&#x8981;&#x8C03;&#x7528;&#x4E0B;&#x8BE5;&#x670D;&#x52A1;
</li>
<li>&#x4EE5;&#x83B7;&#x53D6;&#x53EF;&#x7528;&#x7684;MPUSH server&#x5217;&#x8868;,&#x7136;&#x540E;&#x6309;&#x987A;&#x5E8F;&#x53BB;&#x5C1D;&#x8BD5;&#x5EFA;&#x7ACB;TCP&#x94FE;&#x63A5;,&#x76F4;&#x5230;&#x94FE;&#x63A5;&#x5EFA;&#x7ACB;&#x6210;&#x529F;
</li></ul>
</blockquote><h2 id="&#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x7684;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;">2. &#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x7684;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;</h2><blockquote><p>&#x63A5;&#x53E3;&#x7C7B;&#x578B;     &#xFF1A;HTTP</p><p>Method       : GET</p><p>&#x53C2;&#x6570;         &#xFF1A;&#x65E0;</p><p>&#x8FD4;&#x56DE;&#x503C;&#x683C;&#x5F0F;   : ip:port,ip:port</p><p>content-type : text/plain;charset=utf-8</p></blockquote><h2 id="&#x670D;&#x52A1;&#x90E8;&#x7F72;">3. &#x670D;&#x52A1;&#x90E8;&#x7F72;</h2><ol><li>&#x4E0B;&#x8F7D;alloc&#x6700;&#x65B0;&#x5305;<a href="https://github.com/mpusher/alloc/releases" target="_blank">https://github.com/mpusher/alloc/releases</a>
</li>
<li>&#x89E3;&#x538B;&#x4E0B;&#x8F7D;&#x7684;tar&#x5305;<code>tar -zvxf alloc-release-x.x.x.tar.gz</code>
</li>
<li>&#x4FEE;&#x6539; conf &#x76EE;&#x5F55;&#x4E0B;&#x7684; <code>vi mpush.conf</code>&#x6587;&#x4EF6;, &#x4FEE;&#x6539;&#x65B9;&#x5F0F;&#x53C2;&#x7167;<code>mpush server</code> &#x90E8;&#x7F72;
</li>
<li>&#x7ED9;bin&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x811A;&#x672C;&#x589E;&#x52A0;&#x6267;&#x884C;&#x6743;&#x9650;<code>chmod u+x *.sh</code>
</li>
<li>&#x6267;&#x884C;<code>./mp.sh start</code> &#x542F;&#x52A8;&#x670D;&#x52A1;, &#x67E5;&#x770B;&#x5E2E;&#x52A9;&#x76F4;&#x63A5;&#x6267;&#x884C;<code>./mp.sh</code> 
</li>
<li><code>cd logs</code>&#x76EE;&#x5F55;&#xFF0C;<code>cat mpush.out</code>&#x67E5;&#x770B;&#x670D;&#x52A1;&#x662F;&#x5426;&#x542F;&#x52A8;&#x6210;&#x529F;
</li></ol>
<h2 id="&#x5BA2;&#x6237;&#x7AEF;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x6D41;&#x7A0B;">4. &#x5BA2;&#x6237;&#x7AEF;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x6D41;&#x7A0B;</h2><p><img src="mpush&#x8FDE;&#x63A5;&#x5EFA;&#x7ACB;&#x6D41;&#x7A0B;.png"></p><h2 id="&#x5B9E;&#x73B0;&#x8BB2;&#x89E3;">5. &#x5B9E;&#x73B0;&#x8BB2;&#x89E3;</h2><ol><li><p>&#x670D;&#x52A1;&#x90E8;&#x7F72;&#x53EF;&#x4EE5;&#x96C6;&#x6210;Tomcat&#x6216;&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;HttpServer&#x6BD4;&#x5982;&#x57FA;&#x4E8E;Netty&#x5B9E;&#x73B0;</p></li>
<li><p>mpush server &#x96C6;&#x7FA4;&#x5217;&#x8868;&#x53EF;&#x4EE5;&#x4ECE;Zookeeper&#x67E5;&#x8BE2;&#xFF0C;&#x76EE;&#x524D;&#x63D0;&#x4F9B;&#x7684;&#x6709;ZK&#x67E5;&#x8BE2;&#x5BA2;&#x6237;&#x7AEF;</p></li>
<li><p>&#x5982;&#x679C;&#x8981;&#x5B9E;&#x73B0;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x53EF;&#x4EE5;&#x8003;&#x8651;&#x4F7F;&#x7528;&#x4EE5;&#x4E0B;&#x51E0;&#x79CD;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;&#xFF1A;</p><blockquote><p>&#x968F;&#x673A;&#xFF0C;&#x6BCF;&#x6B21;&#x4ECE;mpush server&#x5217;&#x8868;&#x968F;&#x673A;&#x9009;&#x53D6;&#x4E00;&#x4E2A;&#x5730;&#x5740;&#x8FD4;&#x56DE;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;</p><p>&#x8F6E;&#x64AD;&#xFF0C;&#x6BCF;&#x6B21;&#x628A;mpush server&#x5217;&#x8868;&#x4F9D;&#x6B21;&#x8FD4;&#x56DE;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;</p><p>&#x6309;&#x94FE;&#x63A5;&#x6570;&#x91CF;&#x6392;&#x5E8F;&#xFF0C;&#x94FE;&#x63A5;&#x6570;&#x5C11;&#x7684;&#x6392;&#x6700;&#x524D;&#x9762;</p></blockquote></li></ol>
<h2 id="Alloc&#x670D;&#x52A1;&#x5B58;&#x5728;&#x7684;&#x610F;&#x4E49;">6. Alloc&#x670D;&#x52A1;&#x5B58;&#x5728;&#x7684;&#x610F;&#x4E49;</h2><p>&#x521A;&#x5F00;&#x59CB;&#x770B;MPUSH&#x7684;&#x7AE5;&#x978B;&#x53EF;&#x80FD;&#x4F1A;&#x6709;&#x7591;&#x95EE;&#xFF0C;&#x8FD9;&#x73A9;&#x610F;&#x6709;&#x4EC0;&#x4E48;&#x7528;&#xFF0C;&#x4E3A;&#x4EC0;&#x4E48;&#x4E0D;&#x76F4;&#x63A5;&#x8FDE;mpush server ?</p><p>&#x5982;&#x679C;&#x76F4;&#x8FDE;&#x4F60;&#x53EF;&#x80FD;&#x9047;&#x5230;&#x4E00;&#x4E9B;&#x95EE;&#x9898;&#xFF0C;&#x6BD4;&#x5982;&#x4F60;&#x7684;mpush server &#x53EF;&#x80FD;&#x4E0D;&#x6B62;&#x4E00;&#x53F0;&#xFF0C;&#x4F60;&#x600E;&#x4E48;&#x53BB;&#x9009;&#x62E9;&#x8FDE;&#x54EA;&#x4E00;&#x53F0;&#xFF1F;</p><p>&#x5176;&#x4E2D;&#x67D0;&#x53F0;&#x670D;&#x52A1;&#x6302;&#x4E86;&#x600E;&#x4E48;&#x529E;&#xFF1F;&#x8981;&#x66F4;&#x6362;&#x673A;&#x5668;&#x53C8;&#x600E;&#x4E48;&#x529E;&#xFF1F;&#x8FD9;&#x65F6;&#x4F60;&#x5FC5;&#x7136;&#x5E0C;&#x671B;&#x6709;&#x4E00;&#x53F0;&#x524D;&#x7F6E;&#x670D;&#x52A1;&#x6765;&#x5BF9;&#x6574;&#x4E2A;mpush&#x96C6;&#x7FA4;&#x8FDB;&#x884C;&#x7EDF;&#x4E00;&#x8C03;&#x5EA6;&#x3002;</p><footer class="page-footer"><span class="copyright">Copyright &#xA9; ohun.com 2016 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2016-09-23 09:48:08
</span></footer>

<div id="anchors-navbar"><i class="fa fa-anchor"></i><ul><p><a href="#Alloc&#x5B9E;&#x73B0;">Alloc&#x5B9E;&#x73B0;</a></p><li><a href="#alloc_&#x7684;&#x4F5C;&#x7528;">1. alloc &#x7684;&#x4F5C;&#x7528;</a></li><li><a href="#&#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x7684;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;">2. &#x5BF9;&#x5916;&#x63D0;&#x4F9B;&#x7684;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;</a></li><li><a href="#&#x670D;&#x52A1;&#x90E8;&#x7F72;">3. &#x670D;&#x52A1;&#x90E8;&#x7F72;</a></li><li><a href="#&#x5BA2;&#x6237;&#x7AEF;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x6D41;&#x7A0B;">4. &#x5BA2;&#x6237;&#x7AEF;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x6D41;&#x7A0B;</a></li><li><a href="#&#x5B9E;&#x73B0;&#x8BB2;&#x89E3;">5. &#x5B9E;&#x73B0;&#x8BB2;&#x89E3;</a></li><li><a href="#Alloc&#x670D;&#x52A1;&#x5B58;&#x5728;&#x7684;&#x610F;&#x4E49;">6. Alloc&#x670D;&#x52A1;&#x5B58;&#x5728;&#x7684;&#x610F;&#x4E49;</a></li></ul></div><a href="#alloc_&#x7684;&#x4F5C;&#x7528;" id="goTop"><i class="fa fa-arrow-up"></i></a>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="chapter14.html" class="navigation navigation-prev " aria-label="Previous page: 7.配置详解">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="chapter15.html" class="navigation navigation-next " aria-label="Next page: 9.Android SDK">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"8.Alloc实现","level":"1.9","depth":1,"next":{"title":"9.Android SDK","level":"1.10","depth":1,"path":"chapter15.md","ref":"chapter15.md","articles":[{"title":"9.1.SDK系统架构","level":"1.10.1","depth":2,"path":"chapter15.1.md","ref":"chapter15.1.md","articles":[]},{"title":"9.2.MpushClient架构","level":"1.10.2","depth":2,"path":"chapter15.2.md","ref":"chapter15.2.md","articles":[]}]},"previous":{"title":"7.配置详解","level":"1.8","depth":1,"path":"chapter14.md","ref":"chapter14.md","articles":[]},"dir":"ltr"},"config":{"plugins":["prism","sharing","search","-highlight","-page-treeview","-anchorjs","baidu","donate","tbfed-pagefooter","navigator","duoshuo","editlink","splitter"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy ohun.com 2016","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{},"editlink":{"label":"编辑本页","multilingual":false,"base":"https://github.com/mpusher/docs/tree/book"},"splitter":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"duoshuo":{"short_name":"mpush","theme":"default"},"donate":{"alipay":"alipay.jpg","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"wxpay.png","wechatText":"微信打赏"},"fontsettings":{"theme":"sepia","family":"sans","size":2},"navigator":{},"baidu":{"token":"74e8d02bb383b3d88072165c31989fb2"},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchorjs":{"icon":"#","placement":"right","visible":"always","class":"custom-class another-one"}},"theme":"default","author":"夜色","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"MPUSH开发文档","language":"zh-hans","gitbook":"*","description":"mpush开发手册"},"file":{"path":"chapter17.md","mtime":"2016-09-23T01:48:08.000Z","type":"markdown"},"gitbook":{"version":"3.2.0","time":"2016-10-26T16:14:58.733Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-baidu/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-duoshuo/duoshuo.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-editlink/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

